<?php


App::import('Controller','Admin');
class LocationController extends AdminController {
    public $uses = array('Location','LocationLanguage');
    
    public function index() {
        App::import('model','Location');
        $out = "";
        Location::generateRow(1, $out,"");
        $this->set('categories',$out);
    }
    
    public function addlocation($locationID=NULL){
        if($this->request->is('post')){
            if($locationID != NULL){
                $this->request->data['Location']['location_id'] = $locationID;
            }
            if($this->Location->save($this->request->data)){
                $this->Session->setFlash(__('Your Location has been saved.'), 'alert', array('plugin' => 'BoostCake','class' => 'alert-success'));
                return $this->redirect(array('action' => 'index'));
            }
        }
        if(!$this->request->data){
            $data = $this->Location->getLocationID($locationID);
            //print_r($data);exit;
            $this->request->data = $data;
        }
        //print_r($this->Location->createTree());exit;
        $this->set('selectlocation',$this->Location->createTree());
    }
    public function deletelocation($id){
        $this->Location->delete($id);
        $this->Session->setFlash(__('Delete Location success.'), 'alert', array('plugin' => 'BoostCake','class' => 'alert-success'));
        
        return $this->redirect(array('action' => 'index'));
    }

}